

if self.env.now > self.pa.episode_max_length:  # run too long, force termination
    done = True

if self.end == "no_new_task":  # end of new job sequence
    pass

    #     # 限制仿真的的整体时长
    #     done = True
elif self.end == "all_done":  # everything has to be finished
    done = True
    # len(self.machine.running_job) == 0 and
    # if self.board.all_planes_finished and \
    #         all(s is None for s in self.task_slot.slot) and \
    #         all(s is None for s in self.task_backlog.backlog):
    #     done = True
    # elif self.env.now > self.pa.episode_max_length:  # run too long, force termination
    #     done = True

if not done:
    # todo:simpy 运行直到事件结束
    if self.board.canMoveOn():
        self.env.run(until=self.events[0])

    if not self.board.all_planes_finished:  # otherwise, end of new job sequence, i.e. no new jobs
        new_task = self.board.next_task()

        if new_task is not None:  # a new job comes

            to_backlog = True
            for i in range(self.pa.num_nw):
                if self.task_slot.slot[i] is None:  # put in new visible job slots
                    self.task_slot.slot[i] = new_task

                    to_backlog = False
                    break

            if to_backlog:
                if self.task_backlog.curr_size < self.pa.backlog_size:
                    self.task_backlog.backlog[self.task_backlog.curr_size] = new_task
                    self.task_backlog.curr_size += 1

                else:  # abort, backlog full
                    print("Backlog is full.")
                    # exit(1)
    else:
        self.end = 'all_done'